class Solution(object):
    def canPlaceFlowers(self, flowerbed, n):
        """
        :type flowerbed: List[int]
        :type n: int
        :rtype: bool
        """
        if n == 0:
            return True
        length = len(flowerbed)
        prev = 0
        count = 0
        for i in range(length):
            if flowerbed[i] == 1:
                prev = 1
            else:
                if prev == 0:
                    if i == length - 1 or flowerbed[i+1] == 0:
                        count += 1
                        if count >= n:
                            return True
                        prev = 1
                    else:
                        prev = 0
                else:
                    prev = 0
        return False